package com.huanletao.spring.scheduling;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.scheduling.support.PeriodicTrigger;

import java.util.Date;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 * </p>
 * package: com.huanletao.spring.scheduling
 * description:
 * className: demo
 * author:  踏雪无痕
 * copyright: Copyright (c) 2022/8/23 11:54
 * since: 1.0.0
 */
public class demo {

    public static void main(String[] args) throws InterruptedException {
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ThreadSchedulerConfig.class);

        ThreadPoolTaskScheduler taskScheduler = ctx.getBean(ThreadPoolTaskScheduler.class);
//        //触发定时任务
//        ScheduledFuture<?> schedule = taskScheduler.schedule(new Job(), new CronTrigger("* * * * * ?"));
//
//        //触发定时任务
//        ScheduledFuture<?> schedule1 = taskScheduler.schedule(new Job(),new Date());
//
//        //间隔时间
        ScheduledFuture<?> schedule2 = taskScheduler.schedule(new Job(),new PeriodicTrigger(1, TimeUnit.SECONDS));

//        ScheduledFuture<?> schedule3 = taskScheduler.scheduleAtFixedRate(new Job(),);


        Thread.sleep(10000);

    //   schedule.cancel(false);
    }
}
